﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace Autobiography.Helpers
{
    public static class VisualTreeExtensions
    {
        public static T GetVisualAncestor<T>(this DependencyObject obj) where T : DependencyObject
        {
            var child = obj;
            while ((child != null) && !(child is T))
            {
                child = VisualTreeHelper.GetParent(child);
            }
            return child as T;
        }

        public static List<DependencyObject> GetVisualAncestors(this DependencyObject obj)
        {
            var child = obj;
            List<DependencyObject> list = new List<DependencyObject>();
            
            while ((child != null))
            {
                list.Add(child);
                child = VisualTreeHelper.GetParent(child);
            }
            return list;
        }
    }
}
